/*
 * @Author: mylesshie@gmail.com
 * @Date: 2020-07-03 11:10:01
 * @LastEditors: mylesshie@gmail.com
 * @LastEditTime: 2020-07-08 10:21:57
 * @description: 
 */ 

import {
  GET_USERINFO,
  GET_FEEDBACK_LIST,
  GET_COLLECTION,
  ADD_HISTORY,
  LOGOUT
} from '@/constants/user'

const INIT_STATE = {
  userInfo: {},
  feedbackList: [],
  collection: []
}

export default function user(state = INIT_STATE, action) {
  switch (action.type) {
    case GET_USERINFO:
      return {
        ...state,
        userInfo: action.data
      }
    case GET_FEEDBACK_LIST:
      return {
        ...state,
        feedbackList: action.data.list
      }
    case GET_COLLECTION:
      return {
        ...state,
        collection: action.data.list
      }
    case ADD_HISTORY:
      
      let thisData = {
        id: action.params.id,
        title: action.params.title,
        coverImgs: action.params.coverImgs,
        type: action.params.type
      }
      console.log('-----------ADD_HISTORY----------:', thisData)
      global.storage.save({
        key: 'historyList',
        id: thisData.id,
        data: thisData
      })

      return state
    case LOGOUT:
      console.log('-------------LOGOUT-------------')
      global.storage.save({
        key: 'loginState',
        data: {}
      })
      return {
        ...state,
        userInfo: {}
      }
    default:
      return state
  }
}